package com.zyd.shiro.persistence.dao;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

import com.zyd.shiro.persistence.beans.Talentshare;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 数据访问接口
 * @author Administrator
 *
 */
public interface MallTalentshareDao extends JpaRepository<Talentshare,Integer>,JpaSpecificationExecutor<Talentshare> {

    @Query(value = "select * from mall_talentshare where state=?1",nativeQuery = true)
    List<Talentshare> getAllByState(Integer state);
    List<Talentshare> getAllByTypeAndMoldAndState(Integer type , Integer mold ,Integer state);
    List<Talentshare> getAllByStateAndMold(Integer state , Integer mold);

    @Query(value = "select * from mall_talentshare ts where ts.user_id=?1", nativeQuery = true)
    List<Talentshare> getAllByUser_id(Integer user_id);

    @Transactional
    @Modifying(clearAutomatically = true)
    @Query(value = "update mall_talentshare  set state=?1 where id=?2 ", nativeQuery = true)
    void updateState(Integer state,Integer id);
}
